package cn.afactory.tygz.model;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;

/**
 * Created with Android Studio.
 * Title:UploadFileInfo
 * Description:
 * Copyright:Copyright (c) 2015
 * Company:和平必胜、正义必胜、人民必胜
 * Author:炎黄子孙
 * Date:15/9/14
 * Time:下午12:54
 * Version 1.0
 */
public class ImageInfo implements Serializable {
    private static final long serialVersionUID = -6006381141981728099L;

    public int fileId = 0;

    public String filePath = null;

    /**
     * 反序列化函数，用于从json字符串反序列化本类型实例
     */
    public static ImageInfo deserialize(String json) throws JSONException {
        if (json != null && !json.isEmpty()) {
            return deserialize(new JSONObject(json));
        }
        return null;
    }

    /**
     * 反序列化函数，用于从json节点对象反序列化本类型实例
     */
    public static ImageInfo deserialize(JSONObject json) throws JSONException {
        if (json != null && json != JSONObject.NULL && json.length() > 0) {
            ImageInfo result = new ImageInfo();

            result.fileId = json.optInt("fileId");

            if (!json.isNull("filePath")) {
                result.filePath = json.optString("filePath", null);
            }

            return result;
        }
        return null;
    }
}
